package com.expense.servlet.message;

import java.io.IOException;
import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.expense.annotation.Column;
import com.expense.entity.MessageInfo;
import com.expense.entity.UserInfo;
import com.expense.services.MessageServices;
import com.expense.servlet.BasicServlet;
import com.expense.util.PaginatedList;

public class MessageServlet extends BasicServlet {

	/**
	 * Constructor of the object.
	 */
	public MessageServlet() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		this.doPost(request, response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html");
		String opt=request.getParameter("opt");
		if(opt!=null&&opt.equals("getlist")){//查询费用信息列表
			this.getList(request, response);
		}else
		{

			
		}
		
	}
	
	public void getList(HttpServletRequest request, HttpServletResponse response)
	{
		UserInfo  loginAdmin=this.getLoginAdmin(request);
		logger.info(loginAdmin.getLoginName()+"查询消息信息列表");
		
		String team=request.getParameter("team");
		String classifyName=request.getParameter("classifyName");
		String begin_generatedDate=request.getParameter("begin_generatedDate");
		String end_generatedDate=request.getParameter("end_generatedDate");
		String balanced=request.getParameter("balanced");
		//获取每页显示的行数  
        int pageSize=10;  
        if(null!=request.getParameter("rows")) {  
        	pageSize=Integer.parseInt(request.getParameter("rows").toString());  
        }  
        int currentPage=1;
        if(null!=request.getParameter("page")) {  
        	currentPage=Integer.parseInt(request.getParameter("page").toString());  
        }  
        String  whereSql="";
        String  orderSql="";
        
        MessageServices service=new MessageServices();
        PaginatedList paginatedList= service.selectPageData(pageSize, currentPage, whereSql, orderSql, MessageInfo.class);
        String data= paginatedList.getGridData();
		logger.info("获取消息列表数据"+data);
        // set response header
        response.setContentType("text/html;charset=UTF-8");  
        response.setHeader("Cache-Control","no-cache");
        // 写入json数据
        try {
			response.getWriter().write(data);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
	}
	
}
